﻿using System;
using NUnit.Framework;
using NamedService.Services;
using Xtensive.Orm;
using Xtensive.Orm.Configuration;

namespace NamedService
{
  public class Program
  {
    [Test]
    public static void Main()
    {
      // Loading domain configuration section with name "Default".
      var domainConfiguration = DomainConfiguration.Load("Default");
      var domain = Domain.Build(domainConfiguration);

      // Accessing domain services
      var superService = domain.Services.Get<IMyDomainService>("Super");
      Assert.IsNotNull(superService);
      Console.WriteLine("Successfully obtained IMyDomainService through Domain.Services");

      var fancyService = domain.Services.Get<IMyDomainService>("Fancy");
      Assert.IsNotNull(fancyService);
      Assert.AreNotSame(superService, fancyService);

      Assert.IsInstanceOf(typeof (MySuperService), superService);
      Console.WriteLine("superService is an instance of MySuperService type");
      Assert.IsInstanceOf(typeof (MyFancyService), fancyService);
      Console.WriteLine("fancyService is an instance of MyFancyService type");
    }
  }
}
